package com.chanricle.mixtoolset.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chanricle.mixtoolset.R;
import com.chanricle.mixtoolset.param.ModuleGroup;

/**
 * Main content buttons adapter
 * @author Chanricle King
 *
 */
public class MainContentButtonAdapter extends BaseAdapter {
	/* The context that use this adapter */
	private Context mContext;
	
	public MainContentButtonAdapter(Context c) {
		mContext = c;
	}
			
	@Override
	public int getCount() {
		return ModuleGroup.modules.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = View.inflate(mContext, R.layout.item_main_gridview, null);
		/* Item container */
		RelativeLayout relativeLayout;
		
		if(convertView == null) { // if it's not recycled, initialize some attributes
			relativeLayout = (RelativeLayout) view.findViewById(R.id.ItemGridView);
			ImageView imageView = (ImageView) relativeLayout.findViewById(R.id.ItemImage);
			TextView textView = (TextView) relativeLayout.findViewById(R.id.ItemText);
			
			imageView.setImageResource(ModuleGroup.modules.keyAt(position));
			textView.setText(ModuleGroup.modules.valueAt(position));
			
		} else {
			relativeLayout = (RelativeLayout) convertView;
		}
		
		return relativeLayout;
	}

}
